Date.prototype.format = function(format) {
  var date = {
    "M+": this.getMonth() + 1,
    "d+": this.getDate(),
    "h+": this.getHours(),
    "m+": this.getMinutes(),
    "s+": this.getSeconds(),
    "q+": Math.floor((this.getMonth() + 3) / 3),
    "S+": this.getMilliseconds()
  };
  if (/(y+)/i.test(format)) {
    format = format.replace(RegExp.$1, (this.getFullYear() + '').substr(4 - RegExp.$1.length));
  }
  for (var k in date) {
    if (new RegExp("(" + k + ")").test(format)) {
      format = format.replace(RegExp.$1, RegExp.$1.length == 1 ?
        date[k] : ("00" + date[k]).substr(("" + date[k]).length));
    }
  }
  return format;
}

function validPhone(phone) {
  return /^1[3456789]\d{9}$/.test(phone);
}

function formatWeekday(day) {
  return ['星期日', '星期一', '星期二', '星期三', '星期四', '星期五', '星期六'][day]
}

function formatGrade(grade) {
  var arr = new Map([
    [1, '一年级'],
    [2, '二年级'],
    [3, '三年级'],
    [4, '四年级'],
    [5, '五年级'],
    [6, '六年级'],
    [7, '初一'],
    [8, '初二'],
    [9, '初三'],
    [10, '高一'],
    [11, '高二'],
    [12, '高三']
  ])
  return arr.get(grade)
}

function formatPhysicalTest(type) {
  var textNameFormat = new Map([
    [1, 'BMI'],
    [2, '肺活量'],
    [3, '50米跑'],
    [4, '立定跳远'],
    [5, '坐位体前屈'],
    [6, '1分钟仰卧起坐'],
    [7, '引体向上'],
    [8, '1000米跑'],
    [9, '800米跑'],
    [12, '8*50米往返跑'],
    [13, '1分钟跳绳']
  ]);
  return textNameFormat.get(type * 1)
}

module.exports = {
  validPhone,
  formatWeekday,
  formatGrade,
  formatPhysicalTest
}